var contacts = (function (){
    var initials = false, cID;
    this.loadContacts = function (clientID){
        cID = clientID;
        dataBase.getClientContacts(cID, function(data){
            var i, num = data.length, str=[];
            for(i=0;i<num;i+=1){
                str.push("<li contactID='" + data[i].ContactID + "'><a  style='display: inline-block; padding: 14px 14px 0px 14px;; font-size: 14px;'>" +
                    data[i].Salutation + " " + data[i].Name + "</a><span style='font-size: 10px; padding-left: 14px; " +
                    "padding-bottom: 14px; display: block;' >" +
                    data[i].Position  + ", " + data[i].Email1 + "</span></li>")
            }
            $("#lstContacts").html(str.join('')).listview('refresh');
        });
        this.initContacts();
    }
    this.initContacts = function (){
        if(!initials){
            $("#lstContacts").delegate("li", "click", function () {
                var conID = parseInt($(this).attr("contactID"));
                addnewcontact.editContact(conID, cID);
                $.mobile.changePage("#pnAddNewClientContact");
                //windows.showPage("pnContacts","pnAddNewClientContact");
            });
            $("#btnAddContact").click( function (){
                addnewcontact.initAddNewContact(cID);
                $.mobile.changePage("#pnAddNewClientContact");
                //windows.showPage("pnContacts","pnAddNewClientContact");
            });
            $("#btnContactsBack").click( function (){

                //windows.return();
                $.mobile.changePage("#pnClient");
            });
        }
        initials = true;
    };
    return this;
}(contacts || {}));
